package cn.iocoder.yudao.module.agent.convert.brokeragerecord;

import java.time.LocalDateTime;
import java.util.*;

import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
import cn.iocoder.yudao.module.agent.dal.dataobject.brokerageuser.AgentBrokerageUserDO;
import cn.iocoder.yudao.module.agent.enums.AgentBrokerageRecordBizTypeEnum;
import cn.iocoder.yudao.module.agent.enums.AgentBrokerageRecordStatusEnum;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import cn.iocoder.yudao.module.agent.controller.admin.brokeragerecord.vo.*;
import cn.iocoder.yudao.module.agent.dal.dataobject.brokeragerecord.AgentBrokerageRecordDO;

/**
 * 代理人佣金记录 Convert
 *
 * @author 曹建伟
 */
@Mapper
public interface AgentBrokerageRecordConvert {

    AgentBrokerageRecordConvert INSTANCE = Mappers.getMapper(AgentBrokerageRecordConvert.class);

    AgentBrokerageRecordDO convert(AgentBrokerageRecordCreateReqVO bean);

    AgentBrokerageRecordDO convert(AgentBrokerageRecordUpdateReqVO bean);

    AgentBrokerageRecordRespVO convert(AgentBrokerageRecordDO bean);

    List<AgentBrokerageRecordRespVO> convertList(List<AgentBrokerageRecordDO> list);

    PageResult<AgentBrokerageRecordRespVO> convertPage(PageResult<AgentBrokerageRecordDO> page);

    List<AgentBrokerageRecordExcelVO> convertList02(List<AgentBrokerageRecordDO> list);

    default  AgentBrokerageRecordDO convert(Long agentUserId,
                                            Long sourceUserId,
                                            AgentBrokerageRecordBizTypeEnum bizType,
                                            Integer brokerageFrozenDay,
                                            LocalDateTime unfreezeTime,
                                            Integer brokerage,
                                            String title,
                                            Long bizId){
        AgentBrokerageRecordDO agentBrokerageRecordDO = new AgentBrokerageRecordDO();

        // 不冻结时，佣金直接就是结算状态
        Integer status = brokerageFrozenDay > 0
                ? AgentBrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus()
                : AgentBrokerageRecordStatusEnum.SETTLEMENT.getStatus();

        agentBrokerageRecordDO.setStatus(status);
        agentBrokerageRecordDO.setAgentUserId(agentUserId);
        agentBrokerageRecordDO.setSourceUserId(sourceUserId);
        agentBrokerageRecordDO.setBizId(bizId);
        agentBrokerageRecordDO.setPrice(brokerage);
        agentBrokerageRecordDO.setTitle(title);
        agentBrokerageRecordDO.setDescription(StrUtil.format(bizType.getDescription(), MoneyUtils.fenToYuanStr(Math.abs(brokerage))));
        agentBrokerageRecordDO.setBrokerage(brokerage);
        agentBrokerageRecordDO.setUnfreezeTime(unfreezeTime);
        agentBrokerageRecordDO.setFrozenDays(brokerageFrozenDay);

        return agentBrokerageRecordDO;
    }

}
